package customer.zspt.cn.customer.components.order.orderVp;

import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import customer.zspt.cn.customer.R;
import customer.zspt.cn.customer.bean.OrderMsgDao;
import customer.zspt.cn.customer.Widget.OrderContentItemView;

/**
 * Created by Administrator on 2018/7/18 0018.
 */

public class OrderFirstVpItem extends BaseVpItem {

    private View view;
    private String[] stateTitle = new String[]{
            "編號","主題","狀態","優先級","技能組"
    };
    //vp第一個頁面
    @ViewInject(R.id.state)
    private LinearLayout state_ll;
    @ViewInject(R.id.content)
    private LinearLayout content_ll;
    @ViewInject(R.id.time)
    private LinearLayout time_ll;

    public OrderFirstVpItem(Activity activity,OrderMsgDao.OrderMsg orderMsg,String guserid) {
        super(activity,orderMsg,guserid);
    }
    @Override
    public View initView() {
        view = View.inflate(mActivity, R.layout.order_view_vp_fs,null);
        ViewUtils.inject(this,view);
        return view;
    }
    @Override
    public void initData() {
        addOrderContentView();
    }
    //添加工單中心
    private void addOrderContentView(){
        state_ll.removeAllViews();
        content_ll.removeAllViews();
        time_ll.removeAllViews();
        OrderContentItemView stateOrderNo = new OrderContentItemView(mActivity);
        stateOrderNo.setTitle(stateTitle[0]);
        stateOrderNo.setContent(mOrderMsg.orderNo);
        state_ll.addView(stateOrderNo);
        OrderContentItemView stateOrderTitle = new OrderContentItemView(mActivity);
        stateOrderTitle.setTitle(stateTitle[1]);
        stateOrderTitle.setContent(mOrderMsg.orderTitle);
        state_ll.addView(stateOrderTitle);
        OrderContentItemView stateOrderStatus = new OrderContentItemView(mActivity);
        stateOrderStatus.setTitle(stateTitle[2]);
        stateOrderStatus.setContent(mOrderMsg.orderStatus==0?
                "未受理":mOrderMsg.orderStatus==1?"已受理":mOrderMsg.orderStatus==2?"已回復":
                mOrderMsg.orderStatus==3?"已解決":mOrderMsg.orderStatus==4?"已超時":"已取消"
        );
        state_ll.addView(stateOrderStatus);
        OrderContentItemView stateOrderPriority = new OrderContentItemView(mActivity);
        stateOrderPriority.setTitle(stateTitle[3]);
        stateOrderPriority.setContent(mOrderMsg.orderPriority==0?"正常":mOrderMsg.orderPriority==1?"急":"加急");
        state_ll.addView(stateOrderPriority);
        OrderContentItemView stateSkill = new OrderContentItemView(mActivity);
        stateSkill.setTitle(stateTitle[4]);
        stateSkill.setContent(mOrderMsg.skillId==0?"售前":mOrderMsg.skillId==1?"售後":"技術");
        state_ll.addView(stateSkill);
        try {
            JSONArray content = new JSONArray(mOrderMsg.orderContent);
            for(int i=0;i<content.length();i++)
            {
                OrderContentItemView orderContent = new OrderContentItemView(mActivity);
                JSONObject item = (JSONObject) content.get(i);
                orderContent.setTitle(item.getString("label"));
                orderContent.setContent(item.getString("value"));
                content_ll.addView(orderContent);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        OrderContentItemView TimeCreate = new OrderContentItemView(mActivity);
        TimeCreate.setTitle("創建時間");
        TimeCreate.setContent(mOrderMsg.orderCreatetime);
        time_ll.addView(TimeCreate);
        if(mOrderMsg.orderReplytime!=null)
        {
            OrderContentItemView TimeReply = new OrderContentItemView(mActivity);
            TimeCreate.setTitle("提單時間");
            TimeCreate.setContent(mOrderMsg.orderReplytime+"");
            time_ll.addView(TimeReply);
        }
        if(mOrderMsg.orderSolvetime!=null)
        {
            OrderContentItemView TimeSolve = new OrderContentItemView(mActivity);
            TimeSolve.setTitle("解決時間");
            TimeSolve.setContent(mOrderMsg.orderSolvetime);
            time_ll.addView(TimeSolve);
        }
        OrderContentItemView TimeLast = new OrderContentItemView(mActivity);
        TimeLast.setTitle("最晚提單時間");
        TimeLast.setContent(mOrderMsg.orderLasttime);
        time_ll.addView(TimeLast);
    }
}
